/**
 * 
 */
package com.iwords.constants;


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.commons.beanutils.BeanUtils;

/**
 * @author       BOLIN.HBC 
 * @time         2011-3-6    
 * @description  静态常量配置       
 */
public class Constants {
	
	public final static Set<String> whiteKey = new HashSet<String>();
	
	static{
		whiteKey.add("userid");
		whiteKey.add("action");
	}

	/** USER--ACTION */
	public final static String LOGIN_ACTION = "login";
	public final static String FIND_ACTION = "find";
	public final static String REGISTER_ACTION = "register";
	public final static String UPDATE_ACTION = "update";
	public final static String ACCOUNT_ACTION = "account";
	public final static String LOGOUT_ACTION = "logout";
	public final static String CHECKUSERNAME_ACTION = "checkun";
	public final static String WORDS_USER_LEARNING_STATUS = "changestatus";
	public final static String FINAL_LEARNING_STATUS = "final";
	
	public final static String FIND_USER_SYSCONFIG = "findconfig";
	
	public final static String SAVE_USER_SYSCONFIG = "saveconfig";
	public final static String GETCONFIG_SYSCONFIG = "getconfig";
	
	public static final String LATEST_FEEDBACK = "fbs";
	public static final String ADD_FEEDBACK = "addfb";
	
	public static final String CHECK_USER_STATUS = "checkstatus"; 
	
	public static final String DELAY_VACATION = "delay";
        
        public static final String USER_LOAD_AD = "loadAd";

	/** WORD--ACTION */

	public final static String WORDS_LIST_ACTION = "list";
	public final static String WORDS_SINGLE_ACTION = "single";
	
	/** SENTENCE--ACTION */

	public final static String SENTENCE_HOT_ACTION = "hot";
	public final static String SENTENCE_ALL_ACTION = "list";
	
	/** SYSLIB--ACTION */
	
	public final static String SYSLIB_LIST_ACTION="list";
	public final static String SYSLIB_SINGLE_ACTION = "single";
	public final static String SYSLIB_CHILDREN_ACTION = "children";
	public final static String SYSLIB_SEARCH_ACTION = "search";

	
	
	/** LEARNINGSTATUS-ACTION */
	
	public final static String LEARNINGSTATUS_MOVE_SYSLIB = "movesyslib";
	public final static String LEARNINGSTATUS_GETALL_NUMBER = "allnumber";
	public final static String LEARNINGSTATUS_GETWORD_BY_LEVEL = "level";
	public final static String LEARNINGSTATUS_CHANGE_WORDSTATUS = "changestatus";
	public final static String LEARNINGSTATUS_LIST = "list";
	public final static String LEARNINGSTATUS_STUDY = "study";
	public final static String LEARNINGSTATUS_NEXT_WORD = "next";

	public final static int USER_LEARNINGSTATUS_DEFAULT_VALUE = 0;
	
	public final static int USER_CONFIG_NUMBER=20;
	
	public final static String USER_CONFIG_NUMBER_KEY="batch_number";
	
	/** EAMITEMS-ACTION */

	public final static String EAMITEMS_LIST_ACTION = "list";
	public final static String EAMITEMS_SINGLE_ACTION = "single";

	
	/** ERROR CODE */
	public final static String ERROR_CODE="操作失败";
	
	
	/** JSONOBJECT */

	public final static String IS_SUCCESS = "isSuccess";
	public final static String DEFAULT_VALUE = "defaultValue";
	public final static String MESSAGE = "message";
	
	
	/** TOKEN */
	public final static String token="aaa111";
	
	/** ITEMTYPE */
	public final static String ITEM_TYPE="ITEMTYPE";
	public final static String ITEM_TYPE_1 = "1";
	public final static String ITEM_TYPE_2 = "2";
	public final static String ITEM_TYPE_3 = "3";
	public final static String ITEM_TYPE_4 = "4";
	
	public final static String ERROR_PAGE_JSP  = "error.jsp";
	public final static String INDEX_PAGE_JSP  = "index.jsp";
	public final static String INDEX_PAGE  = "index";
	public final static String LOGIN_PAGE_JSP  = "login.jsp";
	public final static String ACCOUNT_PAGE_JSP  = "account.jsp";
	public final static String ACCOUNT_SETTING_JSP  = "setting.jsp";
    public final static String PAGE_REGISTER_JSP  = "register.jsp";
	public final static String CHOOSE_PAGE_JSP  = "choose.jsp";
	public final static String WORD_JSP  = "words.jsp";
	public final static String CURRENT_WORD_JSP  = "currentWord.jsp";
	public static final String SHOW_LIBS = "showlibs.jsp";
	
	/**DIRECT*/
	
	public static final String UP_TYPE="0";
	public static final String DOWN_TYPE="1";
	public static final String LEFT_TYPE="2";
	public static final String RIGHT_TYPE="3";
	
	 /** DICT.CN */
	public final static String DICT_CN_SEARCH_WORD="http://dict.cn/ws.php?q=";
	public final static String DICT_CN_SEARCH_DEF="</def>";
	public final static String DICT_CN_SEARCH_DEF_="<def>";
	
	/**USER_SYS_CONFIG*/
	public final static String USER_CONFIG_TODAY_KEY="DAY_SURPLUS_NUMBER";
	

    public static String SENTENCE_INDEX = "D:\\dev\\javaWorkSpace\\study\\iwordsSentenceIndex";

    public static String ITEM_INDEX ="D:\\dev\\javaWorkSpace\\study\\iwordsItemIndex";

    public static String DEPLOY_MODE ="real";

    public void setSENTENCE_INDEX(String SENTENCE_INDEX) {
        Constants.SENTENCE_INDEX = SENTENCE_INDEX;
    }

    public void setITEM_INDEX(String ITEM_INDEX) {
        Constants.ITEM_INDEX = ITEM_INDEX;
    }

    public void setDEPLOY_MODE(String DEPLOY_MODE) {
        Constants.DEPLOY_MODE = DEPLOY_MODE;
    }

    static {
		getPropertyValue("/constants.properties");// 从constans.properties读取value，将常量重新赋值
	}

	public static void getPropertyValue(String fileName) {
		try {
            Properties props = new Properties();
            InputStream is = Constants.class.getResourceAsStream(fileName);
            Reader reader = new InputStreamReader(is, "UTF-8");
            props.load(reader);

            Map map = new HashMap();
            Constants constants = new Constants();
            Enumeration enums = props.propertyNames();
            while (enums.hasMoreElements()) {
                String key = (String) enums.nextElement();
                map.put(key, props.getProperty(key.toUpperCase()));
            }
            BeanUtils.copyProperties(constants, map);
            is.close();
            reader.close();
        } catch (Exception e) {
			e.printStackTrace();
		}
	}
}
